
<cfcomponent displayname="customerGateway" output="false">
	<cffunction name="init" access="public" output="false" returntype="model.customer.customerGateway">
		<cfargument name="transfer" type="transfer.com.Transfer" required="true" />
		<cfset variables.transfer = arguments.transfer />
		<cfreturn this />
	</cffunction>
	
	<cffunction name="getByAttributesQuery" access="public" output="false" returntype="query">
		<cfargument name="cust_notes" type="string" required="false" />
		<cfargument name="cus_sysid" type="numeric" required="false" />
		<cfargument name="cus_name_first" type="string" required="false" />
		<cfargument name="cus_name_last" type="string" required="false" />
		<cfargument name="cus_full_name" type="string" required="false" />
		<cfargument name="cus_address" type="string" required="false" />
		<cfargument name="cus_city" type="string" required="false" />
		<cfargument name="cus_state" type="string" required="false" />
		<cfargument name="cus_zip_code" type="string" required="false" />
		<cfargument name="cus_zip_plus" type="string" required="false" />
		<cfargument name="cus_areacode" type="numeric" required="false" />
		<cfargument name="cus_phonenum" type="numeric" required="false" />
		<cfargument name="cus_first_contact" type="numeric" required="false" />
		<cfargument name="cus_notes_q" type="boolean" required="false" />
		<cfargument name="orderby" type="string" required="false" default="customer.cus_sysid" />
		
		<cfset var qList = "" />
		<cfset var tQuery = "" />	
		<cfsavecontent variable="qList">
		<cfoutput>
			FROM		customer.customer AS customer
			WHERE		customer.cus_sysid IS NOT NULL
		<cfif structKeyExists(arguments,"cust_notes") and len(arguments.cust_notes)>
			AND		customer.cust_notes = :cust_notes
		</cfif><cfif structKeyExists(arguments,"cus_sysid") and len(arguments.cus_sysid)>
			AND		customer.cus_sysid = :cus_sysid
		</cfif><cfif structKeyExists(arguments,"cus_name_first") and len(arguments.cus_name_first)>
			AND		customer.cus_name_first = :cus_name_first
		</cfif><cfif structKeyExists(arguments,"cus_name_last") and len(arguments.cus_name_last)>
			AND		customer.cus_name_last = :cus_name_last
		</cfif><cfif structKeyExists(arguments,"cus_full_name") and len(arguments.cus_full_name)>
			AND		customer.cus_full_name = :cus_full_name
		</cfif><cfif structKeyExists(arguments,"cus_address") and len(arguments.cus_address)>
			AND		customer.cus_address = :cus_address
		</cfif><cfif structKeyExists(arguments,"cus_city") and len(arguments.cus_city)>
			AND		customer.cus_city = :cus_city
		</cfif><cfif structKeyExists(arguments,"cus_state") and len(arguments.cus_state)>
			AND		customer.cus_state = :cus_state
		</cfif><cfif structKeyExists(arguments,"cus_zip_code") and len(arguments.cus_zip_code)>
			AND		customer.cus_zip_code = :cus_zip_code
		</cfif><cfif structKeyExists(arguments,"cus_zip_plus") and len(arguments.cus_zip_plus)>
			AND		customer.cus_zip_plus = :cus_zip_plus
		</cfif><cfif structKeyExists(arguments,"cus_areacode") and len(arguments.cus_areacode)>
			AND		customer.cus_areacode = :cus_areacode
		</cfif><cfif structKeyExists(arguments,"cus_phonenum") and len(arguments.cus_phonenum)>
			AND		customer.cus_phonenum = :cus_phonenum
		</cfif><cfif structKeyExists(arguments,"cus_first_contact") and len(arguments.cus_first_contact)>
			AND		customer.cus_first_contact = :cus_first_contact
		</cfif><cfif structKeyExists(arguments,"cus_notes_q") and len(arguments.cus_notes_q)>
			AND		customer.cus_notes_q = :cus_notes_q
		</cfif>
		<cfif structKeyExists(arguments, "orderby") and len(arguments.orderBy)>
			ORDER BY #arguments.orderby#
		</cfif>
		</cfoutput>
		</cfsavecontent>
		<cfset tQuery = variables.transfer.createQuery(qList) />
		<cfif structKeyExists(arguments,"cust_notes") and len(arguments.cust_notes)>
			<cfset tQuery.setParam("cust_notes",arguments.cust_notes) />
		</cfif>
		<cfif structKeyExists(arguments,"cus_sysid") and len(arguments.cus_sysid)>
			<cfset tQuery.setParam("cus_sysid",arguments.cus_sysid) />
		</cfif>
		<cfif structKeyExists(arguments,"cus_name_first") and len(arguments.cus_name_first)>
			<cfset tQuery.setParam("cus_name_first",arguments.cus_name_first) />
		</cfif>
		<cfif structKeyExists(arguments,"cus_name_last") and len(arguments.cus_name_last)>
			<cfset tQuery.setParam("cus_name_last",arguments.cus_name_last) />
		</cfif>
		<cfif structKeyExists(arguments,"cus_full_name") and len(arguments.cus_full_name)>
			<cfset tQuery.setParam("cus_full_name",arguments.cus_full_name) />
		</cfif>
		<cfif structKeyExists(arguments,"cus_address") and len(arguments.cus_address)>
			<cfset tQuery.setParam("cus_address",arguments.cus_address) />
		</cfif>
		<cfif structKeyExists(arguments,"cus_city") and len(arguments.cus_city)>
			<cfset tQuery.setParam("cus_city",arguments.cus_city) />
		</cfif>
		<cfif structKeyExists(arguments,"cus_state") and len(arguments.cus_state)>
			<cfset tQuery.setParam("cus_state",arguments.cus_state) />
		</cfif>
		<cfif structKeyExists(arguments,"cus_zip_code") and len(arguments.cus_zip_code)>
			<cfset tQuery.setParam("cus_zip_code",arguments.cus_zip_code) />
		</cfif>
		<cfif structKeyExists(arguments,"cus_zip_plus") and len(arguments.cus_zip_plus)>
			<cfset tQuery.setParam("cus_zip_plus",arguments.cus_zip_plus) />
		</cfif>
		<cfif structKeyExists(arguments,"cus_areacode") and len(arguments.cus_areacode)>
			<cfset tQuery.setParam("cus_areacode",arguments.cus_areacode) />
		</cfif>
		<cfif structKeyExists(arguments,"cus_phonenum") and len(arguments.cus_phonenum)>
			<cfset tQuery.setParam("cus_phonenum",arguments.cus_phonenum) />
		</cfif>
		<cfif structKeyExists(arguments,"cus_first_contact") and len(arguments.cus_first_contact)>
			<cfset tQuery.setParam("cus_first_contact",arguments.cus_first_contact) />
		</cfif>
		<cfif structKeyExists(arguments,"cus_notes_q") and len(arguments.cus_notes_q)>
			<cfset tQuery.setParam("cus_notes_q",arguments.cus_notes_q) />
		</cfif>
		
		<cfreturn variables.transfer.listByQuery(tQuery) />
	</cffunction>

	<cffunction name="getByAttributes" access="public" output="false" returntype="array">
		<cfargument name="cust_notes" type="string" required="false" />
		<cfargument name="cus_sysid" type="numeric" required="false" />
		<cfargument name="cus_name_first" type="string" required="false" />
		<cfargument name="cus_name_last" type="string" required="false" />
		<cfargument name="cus_full_name" type="string" required="false" />
		<cfargument name="cus_address" type="string" required="false" />
		<cfargument name="cus_city" type="string" required="false" />
		<cfargument name="cus_state" type="string" required="false" />
		<cfargument name="cus_zip_code" type="string" required="false" />
		<cfargument name="cus_zip_plus" type="string" required="false" />
		<cfargument name="cus_areacode" type="numeric" required="false" />
		<cfargument name="cus_phonenum" type="numeric" required="false" />
		<cfargument name="cus_first_contact" type="numeric" required="false" />
		<cfargument name="cus_notes_q" type="boolean" required="false" />
		<cfargument name="orderby" type="string" required="false" />
		
		<cfset var qList = getByAttributesQuery(argumentCollection=arguments) />		
		<cfset var arrObjects = arrayNew(1) />
		<cfset var tmpObj = "" />
		<cfset var i = 0 />
		<cfloop from="1" to="#qList.recordCount#" index="i">
			<cfset tmpObj = variables.transfer.get("customer.customer",qList.cus_sysid[i]) />
			<cfset arrayAppend(arrObjects,tmpObj) />
		</cfloop>
				
		<cfreturn arrObjects />
	</cffunction>

</cfcomponent>
